<template>
	<view>
		<view class="topfixed">
			<view class="search_top">
				<uni-icons type="search" size="24" color="#D1CDCD"></uni-icons>
				<input auto-focus placeholder-class="inputclass" placeholder="搜索" v-model="inputClearValue"
					confirm-type="search" @confirm='confirminput' @input="changevalue" />
				<uni-icons v-if="showClearIcon" color="#D1CDCD" type="clear" size="24" @click="clearIcon"></uni-icons>
			</view>
		</view>
		<view class="search_ls" v-if="historyList.length !=0 &&keyWord ==''">
			<view class="tit">
				搜索历史
				<!-- <uni-icons type="trash" size="20" color="#D1CDCD"></uni-icons> -->
			</view>
			<view class="titflex">
				<view class="itt" v-for="(item,index) in historyList" :key="index" @click="tipclick(item)">
					{{item}}
				</view>
			</view>
		</view>
		<view class="" v-if="type =='1'">
			<view class="itemss" v-for="(item,index) in data.ulist" :key="index">
				<image class="img" :src="item.avatar_text" mode="aspectFill"></image>
				<view class="items_r">
					<view class="items_r_1 flex_jc_sb">
						<view class="flex">
							<view class="name">{{item.name}}</view>
							<view class="huiy">第{{item.meeting_num}}期会员</view>
						</view>
						<view class="flex">
							<view class="btn" @click.stop="copyFun(item.wechat,'微信已复制')">
								<uni-icons type="weixin" color="#fff" size="13"></uni-icons>
								微信
							</view>
							<view class="btn btn1" @click="phoneCall(item.mobile)">
								<uni-icons type="phone-filled" color="#fff" size="13"></uni-icons>
								电话
							</view>
						</view>
					</view>
					<view class="items_r_2">
						<image src="/static/l.png" mode=""></image>
						<span class="">
							{{item.company_name}}·{{item.company_job}}
						</span>
					</view>
					<scroll-view :scroll-x="true" class="scllow">
						<view class="tipitem" v-for="tags in item.tags_text">
							{{tags}}
						</view>
					</scroll-view>
					<view class="items_r_3">
						<image src="/static/c2.png" mode=""></image>
						{{item.city}}
					</view>
				</view>
			</view>
		</view>
		<view class="" v-else>
			<view class="item" v-for="(item,index) in data.ulist" :key="index">
				<image :src="item.image_text" mode="aspectFill"></image>
				<view class="title">
					{{item.title}}
				</view>
				<view class="flex" style="margin-top: 20rpx;">
					<image class="icon" src="/static/c1.png" mode=""></image>
					<view class="text">
						{{time(item.start_time)}}
					</view>
				</view>
				<view class="flex_jc_sb" >
					<view class="flex" style="margin-top: 20rpx;">
						<image class="icon" src="/static/c2.png" mode=""></image>
						<view class="text">
							{{item.city}}
						</view>
					</view>
					<view class="btns b1" v-if="item.state_text == 2&&item.meetorder_start == 3">
						已报名
					</view>
					<view class="btns b3" v-if="item.state_text == 2&&item.meetorder_start != 3">
						报名中
					</view>
					<view class="btns b4" v-if="item.state_text == 1">
						未开始
					</view>
					<view class="btns b4" v-if="item.state_text == 3">
						已结束
					</view>
				</view>
			</view>
		</view>
		<view class="" style="height: 66rpx;">
			
		</view>
		<view class="k1" v-if="keyWord && data.ulist.length == 0">
			<image src="/static/skong.png" mode=""></image>
			<view class="texts">
				暂无搜索内容
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		reactive,
		ref,
		computed
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		getCircleList,getMeetingList
	} from '@/common/http.api.js';
	const time = computed(() => {
		return (tt) => {
			let timenum = tt * 1000
			const date = new Date(timenum);
			// 补零函数
			const padZero = num => num.toString().padStart(2, '0');
			// 提取日期各部分
			const year = date.getFullYear();
			const month = padZero(date.getMonth() + 1); // 月份从0开始需+1
			const day = padZero(date.getDate());
			const hours = padZero(date.getHours());
			const minutes = padZero(date.getMinutes());
			const seconds = padZero(date.getSeconds());
			// 周几映射（0: 周日，1: 周一，...）
			const weekdays = ['日', '一', '二', '三', '四', '五', '六'];
			const weekday = weekdays[date.getDay()];
			// 拼接格式：YYYY-MM-DD HH:mm:ss 周X
			return `${month}/${day} ${hours}:${minutes} | 周${weekday}`;
		}
	})
	const inputClearValue = ref('')
	const showClearIcon = ref(false)
	const keyWord = ref('')
	const historyList = ref([])
	const type = ref(1)
	
	
	const data =reactive({
		ulist:[]
	})
	onLoad((option) => {
		console.log(option);
		// type = 1 圈子  2 大会
		type.value = option.type
		if(option.type == 1){
			historyList.value = uni.getStorageSync('friendList') ? uni.getStorageSync('friendList') : []
		}else{
			historyList.value = uni.getStorageSync('historyList') ? uni.getStorageSync('historyList') : []
		}
	})
	
	
	function getList(){
		if(type.value == 1){
			getCircleList({search:inputClearValue.value}).then(res=>{
				data.ulist.push(...res.data)
			})
		}else{
			getMeetingList({search:inputClearValue.value}).then(res=>{
				data.ulist.push(...res.data)
			})
		}
	}
	function changevalue(e) {
		if (e.detail.value != '') {
			showClearIcon.value = true;
		} else {
			showClearIcon.value = false;
			inputClearValue.value = ''
		}
	}
	function clearIcon() {
		showClearIcon.value = false
		inputClearValue.value = ''
		keyWord.value = ''
		data.ulist = []
	}
	
	function tipclick(item){
		inputClearValue.value = item
		keyWord.value = item
		showClearIcon.value = true;
		data.ulist = []
		getList()
	}
	function confirminput(e) {
		keyWord.value = e.detail.value
		let index = historyList.value.findIndex(item => item === e.detail.value)
		//1 判断在不在 在就不添加
		//2 判断长度大于6就删除第一个在增加
		if (index == -1) {
			if (historyList.value.length >= 6) {
				historyList.value.shift()
				historyList.value.push(keyWord.value)
			} else {
				historyList.value.push(keyWord.value)
			}
		}
		data.ulist = []
		getList()
		if(type.value == 1){
			uni.setStorageSync('friendList', historyList.value)
		}else{
			uni.setStorageSync('historyList', historyList.value)
		}
	}
	
	
	function phoneCall(number){
		if(uni.getStorageSync('cirleToken')){
			if(uni.getStorageSync('user').is_circle==0){
				uni.showModal({
					title:'系统提示',
					content: '此功能需要入圈后访问！',
					confirmText:'申请入圈',
					confirmColor:'#0756FF',
					success: (res) => {
						if (res.confirm) {
							uni.navigateTo({
								url:'/pages/user/apply'
							})
						} else if (res.cancel) {}
					}
				});
			}else{
				uni.makePhoneCall({
					phoneNumber: number, //仅为示例
					success: function() {
						console.log('success');
					}
				});
			}
		}else{
			uni.navigateTo({
				url: '/pages/login/login'
			})
		}
	}
	function copyFun(text,message){
		if(uni.getStorageSync('cirleToken')){
			if(uni.getStorageSync('user').is_circle == 0){
				uni.showModal({
					title:'系统提示',
					content: '此功能需要入圈后访问！',
					confirmText:'申请入圈',
					confirmColor:'#0756FF',
					success: (res) => {
						if (res.confirm) {
							uni.navigateTo({
								url:'/pages/user/apply'
							})
						} else if (res.cancel) {}
					}
				});
			}else{
				uni.setClipboardData({
					data:text, // 要复制的内容
					success: () => { // 复制成功回调
						uni.showToast({
							title:message,
							icon: 'success'
						})
					}
				});
			}
		}else{
			uni.navigateTo({
				url: '/pages/login/login'
			})
		}
		
	}
</script>

<style lang="scss">
	page {
		background: #F7F8FC;
	}
	.k1 {
		text-align: center;
		margin: 120rpx auto;
		width: 360rpx;
		image {
			width: 360rpx;
			height: 360rpx;
		}
		.texts {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #979797;
			margin-top: 10rpx;
		}
	}

	.topfixed {
		width: 100%;
		position: sticky;
		top: 0;
		background-color: #F7F8FC;
		padding: 20rpx;
		box-sizing: border-box;
		z-index: 99;
	}

	.search_top {
		width: 710rpx;
		height: 80rpx;
		background: #fff;
		border-radius: 118rpx 118rpx 118rpx 118rpx;
		display: flex;
		align-items: center;
		padding: 0rpx 22rpx;
		box-sizing: border-box;

		.inputclass {
			font-weight: 500;
			font-size: 28rpx;
			color: #D1CDCD;
		}

		input {
			flex: 1;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #000;
			padding-left: 10rpx;
		}
	}

	.search_ls {
		padding: 0rpx 40rpx;
		box-sizing: border-box;

		.tit {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #000000;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.titflex {
			display: flex;
			margin-top: 20rpx;
			flex-wrap: wrap;
		}

		.itt {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 26rpx;
			color: #000000;
			line-height: 50rpx;
			height: 50rpx;
			background: #fff;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			padding: 0rpx 20rpx;
			margin: 10rpx 20rpx 10rpx 0rpx;
		}
	}
	
	.item {
		width: 710rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: 0rpx auto 20rpx;
		padding: 20rpx;
		box-sizing: border-box;
		image {
			width: 670rpx;
			height: 320rpx;
			border-radius: 20rpx;
		}
	
		.title {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #000000;
		}
	
		.icon {
			width: 28rpx;
			height: 28rpx;
		}
	
		.text {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #616169;
			margin-left: 10rpx;
		}
	
		.btns {
			width: 150rpx;
			height: 64rpx;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			text-align: center;
			line-height: 64rpx;
			font-size: 30rpx;
		}
		.b1{
			background: #FFFFFF;
			border: 1px solid #0756FF;
			color: #0756FF;
		}
		.b2{
			background: #FF2352;
			color: #fff;
		}
		.b3{
			background: #0756FF;
			color: #fff;
		}
		.b4{
			background: #D1D1D6;
			color: #fff;
		}
	}
	
	
	.itemss {
		width: 710rpx;
		height: 240rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 20rpx auto;
		padding: 10rpx;
		box-sizing: border-box;
		display: flex;
	
		.img {
			width: 140rpx;
			height: 220rpx;
			border-radius: 12rpx;
		}
	
		.items_r {
			margin-left: 14rpx;
			flex: 1;
			.items_r_1 {
				margin-top: 8rpx;
	
				.name {
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 32rpx;
					color: #000000;
					margin-right: 16rpx;
				}
	
				.huiy {
					height: 40rpx;
					background: linear-gradient(223deg, #FFC393 0%, #FFE9D9 100%);
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					border: 1px solid #F9B781;
					padding: 0rpx 10rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 20rpx;
					color: #8A3E00;
					line-height: 40rpx;
				}
	
				.btn {
					width: 120rpx;
					height: 48rpx;
					background: #08C985;
					border-radius: 40rpx 40rpx 40rpx 40rpx;
					line-height: 48rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #FFFFFF;
					text-align: center;
				}
				.btn1{
					background: #0756FF !important;
					margin-left: 10rpx;
				}
			}
	
			.items_r_2 {
				margin: 10rpx auto;
				height: 36rpx;
				background: #F4F4FB;
				border-radius: 4rpx 4rpx 4rpx 4rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 22rpx;
				color: #9090A0;
				padding: 0rpx 10rpx;
				display: inline-block;
	
				image {
					width: 24rpx;
					height: 24rpx;
					margin-right: 6rpx;
					margin-top: 4rpx;
				}
			}
	
			.items_r_3 {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #0756FF;
				margin-top: 20rpx;
	
				image {
					width: 24rpx;
					height: 24rpx;
					margin-right: 6rpx;
				}
			}
	
			.scllow {
				width: 520rpx;
				height: 50rpx;
				white-space: nowrap;
	
				.tipitem {
					display: inline-block;
					height: 40rpx;
					background: #EFF4FF;
					border-radius: 20rpx 20rpx 20rpx 20rpx;
					border: 1px solid #66ADFF;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 22rpx;
					color: #529FF8;
					line-height: 40rpx;
					padding: 0rpx 15rpx;
					margin-right: 10rpx;
				}
			}
	
		}
	}
</style>